package com.hz.Tech2Real.yeyouwang.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hz.Tech2Real.yeyouwang.service.loginService;
import com.hz.Tech2Real.yeyouwang.service.Impl.loginServiceImpl;
import com.hz.Tech2Real.yeyouwang.util.CodeUtil;
import com.hz.Tech2Real.yeyouwang.util.Conts;
import com.hz.Tech2Real.yeyouwang.util.Mycons;
import com.hz.Tech2Real.yeyouwang.util.SendMessageUtil;

public class Tech2RealZCServlet extends HttpServlet{

	private static final long serialVersionUID = -6037168209512456998L;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String phone = request.getParameter("phone"); //获取页面手机号
		System.out.println(phone);
		int code = CodeUtil.getCode();  //获取随机数
		System.out.println();
		String content = Mycons.getChangeMsg(code); //获取短信内容
		
		
		String codes =SendMessageUtil.sendMes(content, phone);//获取第三方提供发送短信的接口
		
		System.err.println(codes);
		
		request.getSession().setAttribute(Conts.CODES, code);
		
		response.getWriter().print(codes);
		
	}	
}
